app.controller("mywallet", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Member/wallet',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
		}
	}).success(function(data) {
		$rootScope.login(data)
		console.log(data)
		$scope.balance = data["list"]["balance"]
		$scope.bean = data["list"]["bean"]
	})
}])
app.controller("bankCard", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$rootScope.page.goshow = true
	var length = localStorage.getItem("length")
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Member/withdraw_bank',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
		}
	}).success(function(data) {
		$scope.list = data["list"]
		$rootScope.page.goshow = false
		$timeout(function() {
			if(!length) {
				$(".backcard").eq(0).find(".iconfont").addClass("active")
			} else {
				$(".backcard").eq(length).find(".iconfont").addClass("active")
			}
			$(".backcard").click(function() {
				console.log($(this).index())
				$(this).find(".iconfont").addClass("active")
				$(this).siblings().find(".iconfont").removeClass("active")
				length: localStorage.setItem("length", $(this).index() - 1)
				$state.go("main.apply")
			})
		}, 100)
	})
}])
app.controller("balance", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Member/wallet_record',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
		}
	}).success(function(data) {
		console.log(data)
		$scope.list = data["list"]
	})
}])
app.controller("Bank", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
		$rootScope.page.showfooter = true;
		$rootScope.page.footer = 'mine';
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Member/user_bank',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
			}
		}).success(function(data) {
			console.log(data)
			$scope.list = data["list"]
			$scope.toDel = function(id) {
				$state.go("main.unbundling", {
					Id: id
				})
			}
		})
	}])
	//删除银行卡
app.controller("unbundling", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
		$rootScope.page.showfooter = true;
		$rootScope.page.footer = 'mine';
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Member/bank_find',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
				Id: $stateParams.Id
			}
		}).success(function(data) {
			$scope.list = data["list"]
			$scope.toDel = function() {
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'Member/unbundle',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						bankId: $stateParams.Id
					}
				}).success(function(data) {
					if(data["status"] == 1) {
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
						$timeout(function() {
							$state.go("main.Bank")
						}, 1000)
					}
				})
			}
		})
	}])
	//添加银行卡
app.controller("chooseBank", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
		$rootScope.page.showfooter = true;
		$rootScope.page.footer = 'mine';
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Member/banks',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
			}
		}).success(function(data) {
			console.log(data)
			$scope.list = data["list"]
			$scope.name = ""
			$scope.sku = ""
			$timeout(function() {
				$(".click_p").click(function() {
					if($(".click_p").find("i").attr("class") == "iconfont icon-combinedshapefuben") {
						$(this).find("i").addClass("icon-jiantouxia").removeClass("icon-combinedshapefuben")
						$(this).parent().find("ul").show()
					} else {
						$(this).find("i").addClass("icon-combinedshapefuben").removeClass("icon-jiantouxia")
						$(this).parent().find("ul").hide()
					}
				})
			}, 200)
			$scope.liclick = function(id, name) {
				$scope.name = name
				$scope.sku = id
				$(".ul_warp").hide()
				$(".click_p").find("i").addClass("icon-combinedshapefuben").removeClass("icon-jiantouxia")
			}
			$(".login_btn").click(function() {
				var card_name = $(".card_name").val()
				var card = $(".card").val()
				var opening = $(".opening").val()
				var tel = $(".tel").val()
				var reg1 = /^\d{19}$/g;; // 以19位数字开头，以19位数字结尾  
				var reg = new RegExp(/^1[34578]\d{9}$/);
				if(!card_name) {
					$(".addressdialog").show();
					$(".addressdialog").html("请输入姓名");
					$(".addressdialog").fadeOut(1200);
				} else {
					if(!reg1.test(card)) {
						$(".addressdialog").show();
						$(".addressdialog").html("请输入正确的银行卡号");
						$(".addressdialog").fadeOut(1200);
					} else {
						if(!$scope.sku) {
							$(".addressdialog").show();
							$(".addressdialog").html("请选择银行类型");
							$(".addressdialog").fadeOut(1200);
						} else {
							if(!opening) {
								$(".addressdialog").show();
								$(".addressdialog").html("请输入开户行");
								$(".addressdialog").fadeOut(1200);
							} else {
								if(!reg.test(tel) || tel.length != 11) {
									$(".addressdialog").show();
									$(".addressdialog").html("请输入正确的手机号");
									$(".addressdialog").fadeOut(1200);
								} else {
									$http({
										method: 'post',
										url: '' + $rootScope.Location + 'Member/b_bankInfo',
										headers: {
											'Content-Type': 'application/x-www-form-urlencoded'
										},
										data: {
											user_Id: localStorage.getItem("user_ID"),
											token: localStorage.getItem("token"),
											card_name: card_name,
											card: card,
											bankId: $scope.sku,
											opening: opening,
											tel: tel
										}
									}).success(function(data) {
										if(data["status"] == 1) {
											$(".addressdialog").show();
											$(".addressdialog").html("添加成功");
											$(".addressdialog").fadeOut(1200);
											$timeout(function() {
												if($stateParams.type == 1) {
													$state.go("main.withdrawal")
												} else {
													$state.go("main.Bank")
												}

											}, 1000)

										} else {
											$(".addressdialog").show();
											$(".addressdialog").html(data["message"]);
											$(".addressdialog").fadeOut(1200);
										}
									})
								}
							}
						}
					}
				}

			})
		})
	}])
	//提现判断是否绑定银行卡页面
app.controller("withdrawal", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
		$rootScope.page.showfooter = true;
		$rootScope.page.footer = 'mine';
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Member/wallet',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
			}
		}).success(function(data) {
			$scope.balance = data["list"]["balance"]
		})
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Member/withdraw_bank',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
			}
		}).success(function(data) {
			$scope.goApply = function() {
				if(!data["list"]) {
					$(".order_del").show()
					$scope.clickYes = function() {
						$state.go("main.chooseBank", {
							type: 1
						})
					}
					$scope.clickNo = function() {
						$(".order_del").hide()
					}
				} else {
					$state.go("main.apply")
				}
			}
		})
	}])
	//提现申请页面
app.controller("apply", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	var length = localStorage.getItem("length")
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Member/withdraw_bank',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
		}
	}).success(function(data) {
		console.log(data)
		if(!length) {
			$scope.name = data["list"][0]["name"]
			$scope.card = data["list"][0]["card"]
			$scope.bank_Id = data["list"][0]["Id"]
		} else {
			$scope.name = data["list"][length]["name"]
			$scope.card = data["list"][length]["card"]
			$scope.bank_Id = data["list"][length]["Id"]
		}
		$(".login_btn").click(function() {
			if(!$(".money_num").val()) {
				$(".addressdialog").show();
				$(".addressdialog").html("提现金额不能为空");
				$(".addressdialog").fadeOut(1200);
			} else {
				$(".order_del").show()
				$(".icon-x").click(function() {
					$(".order_del").hide()
				})
				$(".psdclick").click(function() {
					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Member/withdraw',
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						data: {
							user_Id: localStorage.getItem("user_ID"),
							token: localStorage.getItem("token"),
							bankId: $scope.bank_Id,
							money: $(".money_num").val()
						}
					}).success(function(data) {
						console.log(data)
						if(data["status"] == 0) {
							$(".addressdialog").show();
							$(".addressdialog").html(data["message"]);
							$(".addressdialog").fadeOut(1200);
						}
						if(data["status"] == 1) {
							$state.go("main.applytrue", {
								money: data["list"]
							})
						}
					})
				})
			}
		})
	})

	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Member/wallet',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
		}
	}).success(function(data) {
		console.log(data)
		$scope.balance = data["list"]["balance"]
	})

}])
app.controller("applytrue", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$scope.money = $stateParams.money
}])